

package com.hazelcast.internal.cluster.fd;

public enum ClusterFailureDetectorType {

    DEADLINE("deadline"), PHI_ACCRUAL("phi-accrual");

    private final String name;

    ClusterFailureDetectorType(String name) {
        this.name = name;
    }

    /**
     * Returns the {@code ClusterFailureDetectorType} identified by the given {@code name} or throws an
     * {@link IllegalArgumentException} if none can be identified. In contrast to {@link #valueOf(String)}, this method
     * does not match on the identifier name ("DEADLINE", "PHI_ACCRUAL"), but rather on the explicitly specified
     * {@link #name} field's value.
     *
     * @param name name of the requested {@code ClusterFailureDetectorType}
     * @return the {@code ClusterFailureDetectorType} identified by the given name.
     */
    public static ClusterFailureDetectorType of(String name) {
        for (ClusterFailureDetectorType fdType : values()) {
            if (fdType.name.equals(name)) {
                return fdType;
            }
        }
        throw new IllegalArgumentException("Unknown failure detector type: " + name);
    }

    @Override
    public String toString() {
        return name;
    }
}
